package com.example.uidemo_01.Activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.example.uidemo_01.R;

public class RadioButtonActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_radio_button);
        
        //定义对象并绑定grp
        RadioGroup rgrp = findViewById(R.id.rgrp);
        rgrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                //获取选中的复选框
                RadioButton rdcheck = findViewById(checkedId);
                String rdtext = rdcheck.getText().toString();
                Toast.makeText(RadioButtonActivity.this, "选中的是"+ rdtext,Toast.LENGTH_SHORT).show();
            }
        });
        
    }
}
